package com.aidex.quartz.task;

import com.aidex.biz.domain.Order;
import com.aidex.biz.domain.UserTixian;
import com.aidex.biz.service.*;
import com.aidex.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 定时任务调度测试
 *
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask {
    public String ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
        return "sdfsdfsdf";
    }

    public void ryParams(String params) {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams() {
        System.out.println("执行无参方法");
    }


    @Autowired
    private CouponInfoService couponInfoService;

    @Autowired
    private BillInfoService billInfoService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private BillInfoDetailsService billInfoDetailsService;
    @Autowired
    private UserTixianService userTixianService;

    @Autowired
    private WxPayService wxPayService;

    /**
     * 优惠券过期计算
     */
    public void updateIsGuoQi() {
        couponInfoService.updateIsGuoQi();
    }

    /**
     * 微信提现的到零钱  一下自动打款
     */
    public void WeChatPayUser() {
        UserTixian userTixian = userTixianService.findByOne();
        if (null != userTixian) {
            wxPayService.transferBatches(userTixian);
        }

    }

    /**
     * 查询批次打款情况 进行处理提现情况
     */

    public void WeChatBatchsDetails() {
        UserTixian userTixian = userTixianService.findByStatus();
        if (null != userTixian) {
            userTixianService.getTransferBatchesDetails(userTixian);
        }
    }

    /**
     * 更新7天与15天未确认的订单为完成状态
     */
    public void updateOrder7DayAnd15Day(){
        orderService.updateBy7Day();
        orderService.updateBy15Day();
    }

    /**
     * 查询已经完成的订单未入帐，进行入账
     */
    public void updateToOrderBill(){
        List<Order> orderList=orderService.findIsNotBillOrder(new Order());
        for(Order order:orderList){
            billInfoDetailsService.orderToBillInfoDetails(order);
        }
        if(orderList.size()>0){
            // 修改订单入账状态
            Map<String,Object> param=new HashMap<>();
            param.put("list",orderList);
            orderService.batchUpdateOrderStatus(param);
        }

    }


    /**
     * 每日23点55 统计各个商家账单信息
     * @return
     */
    public void taskGetDayBillDetails() {
        billInfoService.getDayBillDetails();
    }

}
